<?php
namespace Systemht\Controller;
use Think\Controller;
class ConfigController extends IndexController{
	public function index(){
		$model = M('Config');
		if(IS_POST){
			$data['title'] = I('post.title');
			$data['keyword'] = I('post.keyword');
			$data['desc'] = I('post.desc');
			//上传logo
			if(isset($_FILES['logo']) && $_FILES['logo']['error'] == 0){
	            $data['logo'] = uploadImage('logo');
	            delImage(I('post.old_logo'));
	        }
			if(false !== $model->where(array('id'=>1))->save($data)){
				$this->success('修改成功',U('index'));
				exit;
			}
			else{
				$this->error('修改失败');
			}
		}
		$data = $model->where(array('id'=>1))->find();
		$this->assign('data',$data);
		// var_dump($data);exit;
		$this->display();
	}

	public function info(){
		$model = M('Config');
		$data['id'] = 1;
		$data['name'] = I('post.name');
		$data['tel'] = I('post.tel');
		$data['chuanzhen'] = I('post.chuanzhen');
		$data['phone'] = I('post.phone');
		$data['email'] = I('post.email');
		$data['company'] = I('post.company');
		$data['website'] = I('post.website');
		$data['address'] = I('post.address');
		$data['beian'] = I('post.beian');
		$data['qq'] = I('post.qq');
		if(false !== $model->save($data)){
			$this->success('修改成功',U('index'));
			exit;
		}
		else{
			$this->error('修改失败');
		}
	}

	//图片设置
	public function setimg(){
		$model = M('Config');
		// var_dump($_POST);exit;
		$data['id'] = 1;
		$data['water'] = I('post.water');
		if(isset($_FILES['w_image']) && $_FILES['w_image']['error'] == 0){
            $data['w_image'] = uploadImage('w_image');
            delImage(I('post.old_w_image'));
        }

		$data['w_opacity'] = I('post.w_opacity');
		$data['w_text'] = I('post.w_text');
		if(false !== $model->save($data)){
			$this->success('修改成功',U('index'));
			exit;
		}
		else{
			$this->error('修改失败');
		}
	}
}